/**
 * 页面中使用到的所有页面路由
 * @Author   ZhaoXianFang
 * @DateTime 2019-09-27
 */
// 按需加载 []标明依赖的模块，这些会提前加载;()回调函数，require的文件会被单独打包成一个chunk;chunk名称
const login = r => require.ensure([], () => (require('@/views/login/login')), 'login')
const register = r => require.ensure([], () => (require('@/views/login/register')), 'register')
const homepage = r => require.ensure([], () => (require('@/views/home/home')), 'home')

const notfount = r => require.ensure([], () => (require('@/views/error/404')), 'notfount')

let sysTitle = '|xxx系统'
// 页面白名单
export const whiteList = [
  '/login',
  '/register',
  '/err'
]

// 默认不需要权限的页面
export const constantRouterMap = [
  {
    path: '/login',
    name: '登录',
    component: login,
    meta: {
      title: '登录' + sysTitle
    }
  },
  {
    path: '/register',
    name: '注册',
    component: register,
    meta: {
      title: '注册' + sysTitle
    }
  },
  {
    path: '/resetpass',
    name: '忘记密码',
    component: register,
    meta: {
      title: '注册' + sysTitle
    }
  },
  {
    path: '/err',
    name: '出错啦',
    component: notfount,
    meta: {
      title: '出错啦' + sysTitle
    }
  },
]

// 异步路由（需要权限的页面）
export const asyncRouterMap = [
  // {
  //   path: '/',
  //   name: '主页',
  //   component: home,
  //   meta: {
  //     permission: [],
  //     title: '主页' + sysTitle
  //   }
  // },
  {
    path: '/home',
    name: '主页',
    component: homepage,
    meta: {
      keepAlive: true, // 缓存
      permission: [],
      title: '主页' + sysTitle
    }
  }
]

// 错误页面路由,例如 /err,/404 ...
export const errRouterMap = [
  {
    path: '*',
    name: 'notfount',
    component: notfount,
    meta: {
      title: '出错啦' + sysTitle
    }
  }
]

// 默认全部导入
export default {
  whiteList,
  constantRouterMap,
  asyncRouterMap,
  errRouterMap
}
